package com.fs.controller.vo.device;

import com.fs.service.bo.device.BoDoorWithState;
import com.fs.service.bo.device.BoSwitchWithState;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

@Data
public class VoDoorState {
    private Integer Id;
    private String name;
    private String onLine;
    private String lock;
    private String lastOnlineTime;
    private String power;

    public VoDoorState(BoDoorWithState bs){
        Id=bs.getDoorId();
        name=bs.getName();
        onLine = bs.isOnline() ? "在线" : "掉线";
        lock = bs.isOpen() ? "解锁" : "上锁";
        lastOnlineTime=bs.getLastOnlineTime();
        power = bs.isBatteryPower() ? "电量正常" : "电量异常";
    }

    public VoDoorState(Integer id, String name) {
        DateTimeFormatter formatter=  DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        setId(id);
        setName(name);
        onLine="在线";
        lock="上锁";
        lastOnlineTime= LocalDateTime.now().minusMinutes(12).format(formatter);
        power="电量正常";
    }
}
